package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.dataConfig.ResponseStatus;
import com.dongdongshop.dataConfig.dataResult;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.util.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("seller")
public class SellerController {
    private Logger logger = LoggerFactory.getLogger(SellerController.class);
    @Reference
    private SellerService sellerService;


    @RequestMapping("toSeller")
    public String toSeller(){
        return "admin/seller";
    }

    @RequestMapping("getinfo")
    @ResponseBody
    public dataResult getinfo(TbSeller t, @RequestParam(defaultValue = "1")Integer number,@RequestParam(defaultValue = "3")Integer pageSize){
        try {
            PageBean<TbSeller> b = sellerService.getinfo(t,number,pageSize);
            return new dataResult(ResponseStatus.SUCCESS.getIndex(), ResponseStatus.SUCCESS.getName(),b);
        }catch (Exception e){
            logger.error("查询失败",e);
            return new dataResult(ResponseStatus.SERVER_ERROR.getIndex(),ResponseStatus.SERVER_ERROR.getName());
        }
    }

    @RequestMapping("toDetail")
    @ResponseBody
    public dataResult toDetail(String sellerId){
        try {
            TbSeller seller = sellerService.toDetail(sellerId);
            return new dataResult(ResponseStatus.SUCCESS.getIndex(), ResponseStatus.SUCCESS.getName(),seller);
        }catch (Exception e){
            logger.error("查询失败",e);
            return new dataResult(ResponseStatus.SERVER_ERROR.getIndex(),ResponseStatus.SERVER_ERROR.getName());
        }
    }

    @RequestMapping("toStatus")
    @ResponseBody
    public dataResult toStatus(TbSeller tbSeller){
        try {
            Integer i = sellerService.toStatus(tbSeller);
            return new dataResult(ResponseStatus.SUCCESS.getIndex(), ResponseStatus.SUCCESS.getName());
        }catch (Exception e){
            logger.error("查询失败",e);
            return new dataResult(ResponseStatus.SERVER_ERROR.getIndex(),ResponseStatus.SERVER_ERROR.getName());
        }
    }

}
